package org.dev.hi.demo

import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import org.dev.hi.R
import org.dev.hi.hiui.tab.common.OnTabSelectedListener
import org.dev.hi.hiui.tab.top.HiTabTopInfo
import org.dev.hi.hiui.tab.top.HiTabTopLayout

/**
 * Author WenPing
 * CreateTime 2021/3/30.
 * Description:
 */
class HiTabTopDemoActivity : AppCompatActivity() {

    val tabStr = arrayOf(
        "热门",
        "服装",
        "数码",
        "鞋子",
        "零食",
        "家电",
        "汽车",
        "百货",
        "家居",
        "装修",
        "运动"
    )

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_hi_tab_top_demo)
        initTabTop()

    }

    private fun initTabTop() {
        val hitabTopLayout = findViewById<HiTabTopLayout>(R.id.tab_top_layout)
        val infoList: MutableList<HiTabTopInfo<*>> = mutableListOf()
        val defaultColor = resources.getColor(R.color.tabBottomDefaultColor)
        val tintColor = resources.getColor(R.color.tabBottomTintColor)

        tabStr.forEach { str ->
            var info = HiTabTopInfo<Int>(str, defaultColor, tintColor)
            infoList.add(info)
        }
        hitabTopLayout.inflateInfo(infoList)
//        hitabTopLayout.addTabSelectedChangeListener(object :OnTabSelectedListener<HiTabTopInfo<*>>{
//            override fun onTabSelectedChange(
//                index: Int,
//                prevInfo: HiTabTopInfo<*>?,
//                nextInfo: HiTabTopInfo<*>) {
//                Toast.makeText(this@HiTabTopDemoActivity, nextInfo.name, Toast.LENGTH_SHORT).show()
//
//            }
//        })
        hitabTopLayout.addTabSelectedChangeListener { index, preInfo, nextInfo ->
            Toast.makeText(this@HiTabTopDemoActivity, nextInfo.name, Toast.LENGTH_SHORT).show()
        }
        hitabTopLayout.defaultSelected(infoList[0])
    }
}